package com.example.nongye.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.jaeger.library.StatusBarUtil;
import com.example.nongye.R;
import com.example.nongye.adapter.HomeBannerAdapter;
import com.example.nongye.databinding.ActivityMainBinding;
import com.tencent.mmkv.MMKV;
import com.zhpan.bannerview.BannerViewPager;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;
    private BannerViewPager<Integer> mViewPager;
    private List<Integer> data = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        StatusBarUtil.setTranslucentForImageView(this, 0, null);
        setupViewPager();

        binding.viewMainAccount.setOnClickListener(view -> startActivity(new Intent(MainActivity.this, LoginActivity.class)));
        binding.viewConf.setOnClickListener(view -> startActivity(new Intent(MainActivity.this, ConfActivity.class)));
        binding.viewMine.setOnClickListener(view -> binding.layoutMine.setVisibility(View.VISIBLE));
        binding.viewHome.setOnClickListener(view -> binding.layoutMine.setVisibility(View.GONE));
        String name = MMKV.defaultMMKV().getString("name", "");

        if (!TextUtils.isEmpty(name) && name.length() > 1) {
            binding.tvName.setText("*" + name.substring(1));
        }
        binding.tvYdzd.setText("您的" + Calendar.getInstance().get(Calendar.MONTH) + "月份账单已出");
    }

    private void setupViewPager() {
        mViewPager = binding.bannerView;
        data.add(R.drawable.img_main_banner_1);
        data.add(R.drawable.img_main_banner_2);
        data.add(R.drawable.img_main_banner_3);
        mViewPager.registerLifecycleObserver(getLifecycle())
                .setInterval(3000)
                .setAdapter(new HomeBannerAdapter())
                .create(data);
    }
}